package ro.isdc.navigator.professor.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import ro.isdc.navigator.misc.domain.SexType;
import ro.isdc.navigator.professor.domain.Professor;

/**
 * Row mapper for the Professor domain object
 * 
 * @author Andrei Chirila / ISDC! Romania
 * @version 1.0
 * @date Jul 8, 2009
 */
public class ProfessorRowMapper implements ParameterizedRowMapper<Professor> {

  @Override
  public Professor mapRow(final ResultSet rs, final int row) throws SQLException {
    Professor prof = new Professor();
    prof.setEntityId(rs.getLong("PROFESSORID"));
    prof.setYearsOfExperience(rs.getInt("YEARSOFEXP"));
    prof.setFirstName(rs.getString("FIRSTNAME"));
    prof.setLastName(rs.getString("LASTNAME"));
    prof.setSSN(rs.getString("SSN"));
    
    SexType sexType = SexType.valueOf(rs.getString("SEX"));
    if (sexType != null) {
      prof.setSexType(sexType);
    }
    prof.setDateOfBirth(rs.getDate("DATEOFBIRTH"));
    prof.setCreatedBy(rs.getLong("CREATEDBY"));
    prof.setLastUpdatedBy(rs.getLong("LASTUPDATEDBY"));
    prof.setVersionNo(rs.getInt("PERSONVERSIONNO"));
    prof.setCreationTimestamp(rs.getTimestamp("CREATIONTIMESTAMP"));
    prof.setLastUpdateTimestamp(rs.getTimestamp("LASTUPDATETIMESTAMP"));

    return prof;
  }

}
